<?php

namespace Test\Unit;

use Design\Structural\Flyweight\TextFactory;

class FlyweightTest extends \Test\BaseTest
{

    private $characters = [
        'a',
        'b',
        'c',
        'd',
        'e',
        'f',
        'g',
        'h',
        'i',
        'j',
        'k',
        'l',
        'm',
        'n',
        'o',
        'p',
        'q',
        'r',
        's',
        't',
        'u',
        'v',
        'w',
        'x',
        'y',
        'z',
    ];

    private $fonts = [
        'Arial',
        'Times New Roman',
        'Verdana',
        'Helvetica',
    ];


    public function testFlyweight()
    {
        $factory = new TextFactory();

        foreach ($this->characters as $char) {
            foreach ($this->fonts as $font) {
                $flyweight = $factory->get($char);

                $this->assertSame(
                    sprintf('Character %s with font %s', $char, $font),
                    $flyweight->render($font)
                );
            }
        }

        foreach ($this->fonts as $font) {
            $flyweight = $factory->get($font);

            $this->assertSame(
                sprintf('Word %s with font %s', $font, 'foo'),
                $flyweight->render('foo')
            );
        }

        $this->assertSame((count($this->characters) + count($this->fonts)), count($factory));

    }//end testFlyweight()


}//end class
